package com.aoyama.kafka.base.gloabl;

import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.clients.producer.RecordMetadata;
import org.springframework.kafka.support.ProducerListener;
import org.springframework.stereotype.Component;


/**
 * 设置全局回调
 * 生产者发送消息后就会自动执行该回调方法
 */
@Slf4j
@Component
public class KafkaSendResultHandler implements ProducerListener {


    @Override
    public void onSuccess(ProducerRecord producerRecord,
                          RecordMetadata recordMetadata) {
        log.info("***** Message send success : " + producerRecord.toString());
    }

    @Override
    public void onError(ProducerRecord producerRecord, Exception exception) {
        log.info("***** Message send error : " + producerRecord.toString());
    }
}
